<?php

namespace App\Http\Middleware;

use Closure;
use App\Services\CommonService;
use Illuminate\Support\Facades\Redis;

class RedisToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $token = $request->header('Authorization');
        if($token){
            if(Redis::exists($token)){
                Redis::expire($token,7200);
            }
            $request->user = json_decode(Redis::get($token),true);
            return $next($request);
        }else{
            return ReturnMsg(CommonService::HTTP_CODE_NOT_LOGIN,'操作失败,请重新登录');
        }

    }
}
